package com.cjkj.equipment.controller;

import com.cjkj.common.core.controller.BaseController;
import com.cjkj.common.core.domain.AjaxResult;
import com.cjkj.common.core.page.TableDataInfo;
import com.cjkj.common.utils.poi.ExcelUtil;
import com.cjkj.equipment.domain.dto.EquipmentCountReq;
import com.cjkj.equipment.domain.vo.EquipmentCountVo;
import com.cjkj.equipment.service.EquipmentCountService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备统计控制器
 */
@RestController
@RequestMapping("/equipment/count")
public class EquipmentCountController extends BaseController {

    @Resource
    private EquipmentCountService equipmentCountService;

    /**
     * 统计列表
     * @param params
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo list(EquipmentCountReq params){
        startPage();
        List<EquipmentCountVo> hospitals = equipmentCountService.getCountList(params);
        return getDataTable(hospitals);
    }

    /**
     * 导出
     * @param params
     * @param response
     */
    @PostMapping("/export")
    public void export(EquipmentCountReq params, HttpServletResponse response){
        List<EquipmentCountVo> hospitals = equipmentCountService.getCountList(params);
        ExcelUtil<EquipmentCountVo> util = new ExcelUtil<>(EquipmentCountVo.class);
        util.exportExcel(response,hospitals,"统计");
    }

    /**
     * 根据医院统计
     * @param params
     * @return
     */
    @GetMapping("/countByHospital")
    public AjaxResult countByHospital(EquipmentCountReq params){
        List<EquipmentCountVo> hospitals = equipmentCountService.getCountByHospital(params);
        return AjaxResult.success(hospitals);
    }

}